import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.table.DefaultTableModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;

/**
 * Patient Invoice Panel
 * 
 * @author Team ThunderDragon
 * @version 1.0
 */
public class PatientInvoicePanel extends JPanel {

	private final JTable table;
	private JTextField textField;

	/**
	 * Patient Invoice Panel constructor.
	 */
	public PatientInvoicePanel() {

		final String[] columnNames = { "Appointment Date", "Doctor Name",
				"Treatments Received", "Billing" };

		final String[][] data = {
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" },
				{ "", "", "", "", "" } };

		table = new JTable(data, columnNames);
		table.setSurrendersFocusOnKeystroke(true);
		table.setCellSelectionEnabled(true);
		table.setColumnSelectionAllowed(true);
		table.setFillsViewportHeight(true);
		table.setModel(new DefaultTableModel(new Object[][] {
				{ "", "", "", "", "" }, { "", "", "", "", "" },
				{ "", "", "", "", "" }, { "", "", "", "", "" },
				{ "", "", "", "", "" }, { "", "", "", "", "" },
				{ "", "", "", "", "" }, { "", "", "", "", "" },
				{ "", "", "", "", "" }, { "", "", "", "", "" }, },
				new String[] { "Date", "Description", "Doctor Name",
						"Prescription", "Billing" }) {
			Class[] columnTypes = new Class[] { String.class, String.class,
					String.class, String.class, String.class };

			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		table.getColumnModel().getColumn(1).setPreferredWidth(100);
		table.getColumnModel().getColumn(2).setPreferredWidth(125);

		final JScrollPane scrollpane = new JScrollPane(table);

		final JLabel lblNewLabel = new JLabel("Patient Invoice");

		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 16));

		final JLabel lblNewLabel_1 = new JLabel("Bill Total:");

		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		textField = new JTextField();
		textField.setHorizontalAlignment(SwingConstants.RIGHT);
		textField.setText("$0.00");
		textField.setEditable(false);
		textField.setColumns(10);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(136)
					.addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 181, GroupLayout.PREFERRED_SIZE))
				.addComponent(scrollpane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(291)
					.addComponent(lblNewLabel_1)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(21)
					.addComponent(lblNewLabel)
					.addGap(6)
					.addComponent(scrollpane, GroupLayout.PREFERRED_SIZE, 185, GroupLayout.PREFERRED_SIZE)
					.addGap(12)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
		);
		setLayout(groupLayout);
	}

	/**
	 * Set the appointment date at the corresponding index.
	 * 
	 * @param appointmentDate
	 *            The appointment date.
	 * @param index
	 *            Index in the table in the appointment data column.
	 */
	public final void setAppointmentDateField(String appointmentDate, int index) {
		table.setValueAt(appointmentDate, index, 0);
	}

	/**
	 * Set the doctor's name at the corresponding index.
	 * 
	 * @param doctorName
	 *            The doctor's name.
	 * @param index
	 *            Index in the table at the doctor's column.
	 */

	/**
	 * Set the description at the corresponding index.
	 * 
	 * @param description
	 *            The specified description
	 * @param index
	 *            Index in the table at the description column.
	 */
	public final void setDescriptionField(String description, int index) {
		table.setValueAt(description, index, 1);
	}

	public final void setDoctorField(String doctorName, int index) {
		table.setValueAt(doctorName, index, 2);
	}

	/**
	 * Set the prescription info at the corresponding index.
	 * 
	 * @param prescription
	 *            The prescription info.
	 * @param index
	 *            The index in the table at the treatments column.
	 */
	public void setPrescription(String prescription, int index) {
		table.setValueAt(prescription, index, 3);
	}

	/**
	 * Set the billing info at the corresponding index.
	 * 
	 * @param billingInfo
	 *            The billing info.
	 * @param index
	 *            The index in the table at the billing column.
	 */
	public void setBillingField(String billingInfo, int index) {
		table.setValueAt(billingInfo, index, 4);
	}
}